<template>
  <div class="container">
    <global-header :user="user"></global-header>
    <Loading v-if="isLoading" text="拼命加载中" background="rgba(0,0,0, 0.8)"></Loading>
    <router-view></router-view>
    <footer class="text-center py-4 text-secondary bg-light mt-6">
      <small>
        <ul class="list-inline mb-0">
          <li class="list-inline-item">© 2020 者也专栏</li>
          <li class="list-inline-item">课程</li>
          <li class="list-inline-item">文档</li>
          <li class="list-inline-item">联系</li>
          <li class="list-inline-item">更多</li>
        </ul>
      </small>
    </footer>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, watch } from 'vue'
import Message from './components/createMessage'

import { useStore } from 'vuex'
import { GlobalDataProps } from './store'
import 'bootstrap/dist/css/bootstrap.min.css'
import Loading from './components/Loading.vue'
import GlobalHeader from './components/GlobalHeader.vue'

export default defineComponent({
  name: 'App',
  components: {
    GlobalHeader,
    Loading
  },
  setup () {
    const store = useStore<GlobalDataProps>()
    // user数据
    const currentUser = computed(() => store.state.user)
    // loading 状态
    const isLoading = computed(() => store.state.isLoading)

    const err = computed(() => store.state.err)

    // 侦听器 侦听err得状态
    watch(() => err.value.isErr, () => {
      const { isErr, message } = err.value
      if (isErr && message) {
        Message(message, 'error')
      }
    })

    return {
      user: currentUser,
      isLoading,
      err
    }
  }
})
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
